package com.example.auth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.auth.entity.AppClient;
import com.example.auth.response.Result;
import com.example.auth.service.AppClientService;
import com.example.auth.mapper.AppClientMapper;
import com.example.auth.util.AppUtils;
import jakarta.annotation.Resource;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
* @author 13057
* @description 针对表【app_client】的数据库操作Service实现
* @createDate 2024-07-09 10:26:43
*/
@Service
public class AppClientServiceImpl extends ServiceImpl<AppClientMapper, AppClient>
    implements AppClientService{
    @Resource
    PasswordEncoder passwordEncoder;

    @Override
    public Result addAuthClient(AppClient appClient) {
        String appKey = AppUtils.getAppId();
        String appSecret = AppUtils.getAppSecret(appKey);
        appClient.setClientId(appKey);
        appClient.setClientSecret(passwordEncoder.encode(appSecret));
        appClient.setClientSecretText(appSecret);
        baseMapper.insert(appClient);
        return Result.OK();
    }
}




